package com.xjtu.weixin.controller.config;

import com.xjtu.weixin.model.entity.MpSubscribe;
import com.xjtu.weixin.model.entity.MpTextTemplate;
import com.xjtu.weixin.service.MpSubscribeService;
import com.xjtu.weixin.service.MpTextTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

/**
 * ${DESCRIPTION}
 *
 * @author 杨凯
 * @create 2018-09-03 16:16
 **/
@Controller
@RequestMapping("/subscribe")
public class SubscribeController {


	@Autowired
	private MpTextTemplateService templateService;

	@Autowired
	private MpSubscribeService subscribeService;

	@GetMapping
	public String index(Model model){
		//获取图文消息列表
		final List<MpTextTemplate> textTemplateList = templateService.getTextTemplateList();
		model.addAttribute("textTemplateList",textTemplateList);
		return "admin/config/subscribe-response";
	}

	/**
	 * 设置关注回复
	 * @param templateId 模板Id
	 * @param msgType 消息类型
	 * @return
	 */
	@PostMapping("/add")
	public ResponseEntity add(String templateId,String msgType){
		MpSubscribe subscribe = new MpSubscribe();
		subscribe.setMsgType(msgType);
		subscribe.setTemplateId(templateId);
		subscribe.setCreateBy("yang kai");
		subscribe.setCreateTime(new Date());
		subscribeService.addMpSubscribe(subscribe);
		return new ResponseEntity("添加成功！",HttpStatus.OK);
	}
}
